﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XYZshell.Game.CardGameEngine
{
	public  class If:RegionActivity
	{

		public If() : base()
		{
		}

		public override void Start()
		{
			IfActivityEventArgs e=new IfActivityEventArgs();
			e.Condition = this.Condition;
			e.Else = this.Else;
			e.Then = this.Then;

			OnStarted( e );
			VariableCollection vars=new VariableCollection( this.Variables );
			if (Condition.Result())
			{

				Then.Variables = vars;
				Then.Start();
			}
			else if (Else != null)
			{
				Else.Variables = vars;
				Else.Start();
			}
			OnFinished( e );
		}

		public ICondition Condition
		{
			get;
			set;
		}

		public IActivity Then
		{
			get;
			set;
		}
		public IActivity Else
		{
			get;
			set;
		}
	}

	public class IfActivityEventArgs : FlowEventArgs
	{
		public ICondition Condition
		{
			get;
			set;
		}

		public IActivity Then
		{
			get;
			set;
		}
		public IActivity Else
		{
			get;
			set;
		}
	}
}
